package com.android.wlw_local.login;

import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.android.wlw_local.R;

public class RegistModelEditText extends LinearLayout implements TextWatcher {
    private Context mContext;
    private EditText et;

    private ImageView iv_left;
    private ImageView iv_right;
    private TextWatcher textWatcher = null;

    public TextWatcher getTextWatcher() {
        return textWatcher;
    }

    public void setTextWatcher(TextWatcher textWatcher) {
        this.textWatcher = textWatcher;
    }

    public RegistModelEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.mContext = context.getApplicationContext();
        initView();
    }

    public void setEditTextAble(boolean enable){
        et.setEnabled(enable);
    }

    public void setEditTextColor(int rcolor){
        et.setTextColor(mContext.getResources().getColor(rcolor));
    }

    private void initView() {
        LayoutInflater.from(mContext).inflate(R.layout.layout_login_model_edittext, this);
        et = (EditText) findViewById(R.id.et);
        et.setHint("请输入账号");
        et.setHintTextColor(mContext.getResources().getColor(R.color.cor_c8c8c8));
        et.addTextChangedListener(this);
        et.setTextColor(mContext.getResources().getColor(R.color.cor_323232));

        iv_left = (ImageView) findViewById(R.id.iv_left);
        iv_left.setImageDrawable(mContext.getResources().getDrawable(R.drawable.sjd_dl_sj));

        iv_right = (ImageView) findViewById(R.id.iv_right);
        iv_right.setImageDrawable(mContext.getResources().getDrawable(R.drawable.edit_delete));

        iv_right.setOnClickListener(new OnClickListener() {
            public void onClick(View arg0) {
                et.setText("");
            }
        });
    }

    public void hideLeftImg(){
        iv_left.setVisibility(View.GONE);
    }
    public void hideRightImg(){
        iv_right.setVisibility(View.GONE);
    }
    public void setLeftimg(int drawable){
        iv_left.setImageDrawable(mContext.getResources().getDrawable(drawable));
    }
    public void setHint(String  hint){
        et.setHint(hint);
    }

    private StringBuilder sb = new StringBuilder();
    private boolean hasSetText = false;
    private int cursor_location = 0;
    private int type = 0;// 添加：1为组内，2为跨组；

    public void afterTextChanged(Editable s) {
        if (textWatcher != null) {
            textWatcher.afterTextChanged(null);
        }
    }

    public void beforeTextChanged(CharSequence s, int start, int count, int after) {


    }

    public void onTextChanged(CharSequence s, int start, int before, int count) {

    }

    public String getText() {
        return et.getText().toString();
    }

    public void setText(String text) {
        et.setText(text);
    }

    public void setInputType(int type) {
        et.setInputType(type);
    }

    public void setMaxLength(int maxLength) {
    }

    public void setDigits(final String digits) {

    }
}
